﻿using System;
using RootfusAddinContracts;
using RootfusAddinView;
using System.AddIn.Pipeline;

namespace RootfusAddinAddinSideAdapters
{
    /// <summary>
    /// Convert a contract to a view.
    /// </summary>
    [HostAdapter]
    public class SICallbackContractToView : SICallback
    {
        ISICallbackContract _contract;
        ContractHandle _handle;

        public SICallbackContractToView(ISICallbackContract contract)
        {
            _contract = contract;
            _handle = new ContractHandle(contract);
        }

        public override void UpdateSaveInformation(string xmltext)
        {
            _contract.UpdateSaveInformation(xmltext);
        }

        public override RootfusAddinView.ROOTObjectSpec[] GetConnectedPinDataAsROOTObject(PinDefinition pin)
        {
            RootfusAddinContracts.ROOTObjectSpec[] rtn = _contract.GetConnectedPinDataAsROOTObject(PinDefinitionHostAdapters.ViewToContract(pin));
            return UtilityConverters.ConvertROOTObjectSpecArray(rtn);
        }

        public override void OutputPinsChanged()
        {
            _contract.OutputPinsChanged();
        }

        public override string[] GetNamesOfConnectedPins(PinDefinition pinDefinition)
        {
            return _contract.GetNamesOfConnectedPins(PinDefinitionHostAdapters.ViewToContract(pinDefinition));
        }
    }
}
